
enum Mode{
    //% block="向上"
   Up,
   //% block="向下"
   Down, 
}
enum Volume{
    //% block="增加"
   Up,
   //% block="减少"
   Down,
}
//% color="#FFA500" iconWidth=50 iconHeight=40
namespace FM {
    //% block="FM收音机初始化" blockType="command"

    export function FMInit(parameter: any, block: any) {

    Generator.addInclude('FM_include', '#include "RDA5807M.h"');
    Generator.addObject(`FM_obj`, `RDA5807M`, `radio;`);
    Generator.addSetup('FM_begin',`radio.begin(RDA5807M_BAND_WEST);`)
    }
    
    //% block="FM收音机[Select]收台" blockType="command"
    //% Select.shadow="dropdown" Select.options="Mode" Select.defl="Mode.向上"
    export function FM_Seek(parameter: any, block: any) {
        let select = parameter.Select.code;

        Generator.addCode(`radio.seek${select}(1);`);
  
     }
    //% block="将FM收音机音量[SELECT] 1" blockType="command"
    //% SELECT.shadow="dropdown" SELECT.options="Volume" SELECT.defl="Volume.增加"
    export function FM_volume(parameter: any, block: any) {
        let se = parameter.SELECT.code;

        Generator.addCode(`radio.volume${se}();`);
  
     }


    //% block="设置收音机频率 [Frequncy] MHZ" blockType="command"
    //% Frequncy.shadow="number" Frequncy.defl="9080" 

    export function FM_setFrequency(parameter: any, block: any) {
        let fre = parameter.Frequncy.code  ;
        
        Generator.addCode(`radio.setFrequency(${fre} );`);
    
        }
    //% block="获取当前收音机频率" blockType="reporter"

    export function FM_getFrequency(parameter: any, block: any) {

        Generator.addCode(`radio.getFrequency()`);
  
     }

  
}